<?php

class Control_Data_showChart
{

    function showChart()
    {
        $action = $this->getValue("action");


        if ($action == 0) {
            $postData['game'] = MooConfig::get('realtimerecharge.defaultGame');
            $realtimerecharge = MooConfig::get('realtimerecharge.url');
            $res = MooUtil::curl_send($realtimerecharge, $postData);

            MooView::set('game', $postData['game']);
            MooView::set('date', date("Y-m-d"));

            MooView::set('year', date("Y"));
            MooView::set('month', date("m"));
            MooView::set('day', date("d"));

            if ($res) {
                MooView::set('realTimedata', $res);
            }

            MooView::render('showChart');
        } else if ($action == 1) {

            $postData = array();

            $nowGame = $postData['game'] = $this->getValue("game");
            $postData['game'] = MooObj::get('Game')->transportGame($postData['game']);

            if ($_REQUEST['platform']) {
                $postData['platform'] = $this->getValue("platform");
            }

            if ($_REQUEST['channel']) {
                $nowChannel = $postData['channel'] = $this->getValue("channel");
                $channel_lang = MooConfig::get("channel_lang.{$game}");
                if ($channel_lang['zh_en'][$postData['channel']]) {
                    $postData['channel'] = $channel_lang['zh_en'][$postData['channel']];
                }
            }

            MooObj::get('Control_Data')->setPlatformData($postData['game']);


            $fetch_tendency = MooConfig::get('main.url.fetch_tendency');


            $res = MooUtil::curl_send($fetch_tendency, $postData);
            //测试数据start
//            $res = array();
//            $start = strtotime("-1 day");
//            for ($i = $start; $i <= time(); $i += 28800) {
//                $res['time'][] = date('Y-m-d H:i:s', $i);
//                $online_num[] = rand(100, 1000);
//                $new_num[] = rand(10, 100);
//                $pay_money[] = rand(100, 1000);
//
//            }
//            $res['data'] = array('online_num' => $online_num, 'new_num' => $new_num, 'pay_money' => $pay_money);
            //测试数据结束

            $legend = array('online_num' => '在线人数', 'new_num' => '新增用户', 'pay_money' => '充值金额');
            $info = array();
            $info['time'] = $res['time'];
            foreach ($legend as $k => $v) {
                $info['content'][] = array('name' => $v, 'type' => 'line', 'data' =>  $res['data'][$k]);
            }
            $info['title'] = $postData['game'] . $postData['platform'] . $postData['channel'];

            echo json_encode($info);


        }
    }

    /**
     * 获取request的值
     * @param unknown $key
     * @return unknown|boolean
     */
    private function getValue($key)
    {
        if (isset($_REQUEST[$key])) {
            return $_REQUEST[$key];
        } else {
            return false;
        }
    }

}